package util;

/**
 * A thread-based singleton to map threads to objects of interest.
 */
public class Cache <T>
{
	/**
	 * Return the value mapped to the current Thread.
	 */
	public T get() {
		return threadMap.get(Thread.currentThread());
	}

	/**
	 * Map an object to the current thread
	 * @param p an object
	 */
	public void put(T p) {
		threadMap.put(Thread.currentThread(), p);
	}
	
	public boolean remove() {
		return threadMap.remove(Thread.currentThread()) != null;
	}

	private final java.util.Map<Thread, T> threadMap = new java.util.HashMap<Thread, T>();
}
